#!/bin/bash

TS_TOPDIR="${0%/*}/../.."
TS_DESC="fstab-bind"

. "$TS_TOPDIR"/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_MOUNT"
ts_check_test_command "$TS_CMD_UMOUNT"
ts_check_test_command "$TS_CMD_FINDMNT"

ts_skip_nonroot
ts_skip_docker

MY_SOURCE="${TS_MOUNTPOINT}-src"

ts_fstab_add $MY_SOURCE "$TS_MOUNTPOINT" "none" "bind,default,noauto"

mkdir -p $MY_SOURCE
mkdir -p $TS_MOUNTPOINT

$TS_CMD_MOUNT -T "$TS_FSTAB" $TS_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
[ "$?" = "0" ] || ts_log "error: mount $TS_MOUNTPOINT"

$TS_CMD_FINDMNT --mountpoint "$TS_MOUNTPOINT" &> /dev/null
[ $? -eq 0 ] || ts_die "Not found target (mount failed?)"

$TS_CMD_UMOUNT $TS_MOUNTPOINT || ts_die "Cannot umount $TS_MOUNTPOINT"

ts_fstab_clean

ts_log "Success"
ts_finalize

